package com.tuananh.radnom.persist;

import java.util.HashMap;

import javax.print.attribute.standard.MediaSize.Engineering;

import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;

import com.tuananh.radnom.model.event.NmsEvent;


public abstract class AbstractPersitor implements Rollbackable,ICommit{
	
	protected AbstractPersitor nextDAO;
	protected Marshaller marshaller;
	protected Unmarshaller unmarshaller;
	public boolean persit() {
		boolean res = true;
		try {
			res = commit();
			if (res && nextDAO!=null)
				res = nextDAO.commit();
		} catch (Exception e) {
			res = false;
		}
		if (!res)
			rollback();
		return true;
	}
	public abstract String getName();
	public static HashMap<String,String> generateHeaders(String...data){
		HashMap<String, String> result = new HashMap<String, String>();
		for(int i=0;i<data.length;i=i+2){
			result.put(data[i], data[i+1]);
		}
		return result;
	}
	protected void reportEvent(Object obj,HashMap<String,String> headers){
		NmsEvent event = new NmsEvent(getName(),obj,headers);
	}
}
